﻿
namespace MyLiveMesh.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using MyLiveMesh.Web.Models;


    // Implements application logic using the ASPNETDBEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class ModelDomainService : LinqToEntitiesDomainService<ASPNETDBEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Files' query.
        public IQueryable<Files> GetFiles()
        {
            return this.ObjectContext.Files;
        }

        public void InsertFiles(Files files)
        {
            if ((files.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(files, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Files.AddObject(files);
            }
        }

        public void UpdateFiles(Files currentFiles)
        {
            this.ObjectContext.Files.AttachAsModified(currentFiles, this.ChangeSet.GetOriginal(currentFiles));
        }

        public void DeleteFiles(Files files)
        {
            if ((files.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Files.Attach(files);
            }
            this.ObjectContext.Files.DeleteObject(files);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'FilesRights' query.
        public IQueryable<FilesRights> GetFilesRights()
        {
            return this.ObjectContext.FilesRights;
        }

        public void InsertFilesRights(FilesRights filesRights)
        {
            if ((filesRights.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(filesRights, EntityState.Added);
            }
            else
            {
                this.ObjectContext.FilesRights.AddObject(filesRights);
            }
        }

        public void UpdateFilesRights(FilesRights currentFilesRights)
        {
            this.ObjectContext.FilesRights.AttachAsModified(currentFilesRights, this.ChangeSet.GetOriginal(currentFilesRights));
        }

        public void DeleteFilesRights(FilesRights filesRights)
        {
            if ((filesRights.EntityState == EntityState.Detached))
            {
                this.ObjectContext.FilesRights.Attach(filesRights);
            }
            this.ObjectContext.FilesRights.DeleteObject(filesRights);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Friends' query.
        public IQueryable<Friends> GetFriends()
        {
            return this.ObjectContext.Friends;
        }

        public void InsertFriends(Friends friends)
        {
            if ((friends.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(friends, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Friends.AddObject(friends);
            }
        }

        public void UpdateFriends(Friends currentFriends)
        {
            this.ObjectContext.Friends.AttachAsModified(currentFriends, this.ChangeSet.GetOriginal(currentFriends));
        }

        public void DeleteFriends(Friends friends)
        {
            if ((friends.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Friends.Attach(friends);
            }
            this.ObjectContext.Friends.DeleteObject(friends);
        }
    }
}


